<#assign ctx=request.contextPath />
<!DOCTYPE html>
<html lang="en">
<head>
    <!-- favicon -->
    <meta charset="utf-8">
    <link rel="icon" href="${ctx}/resource/img/favicon.ico" type="image/x-icon"/>
    <link rel="shortcut icon" href="${ctx}/resource/img/favicon.ico" type="image/x-icon"/>
    <link rel="bookmark" href="${ctx}/resource/img/favicon.ico" type="image/x-icon"/>
    <meta charset="utf-8">
    <#include '${ctx}/sys/include/common-css.html' />
    <style type="text/css">
        .container {
            width: 420px;
            height: 270px;
            min-height: 270px;
            max-height: 270px;
            position: absolute;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            margin: auto;
            padding: 20px;
            z-index: 130;
            border-radius: 8px;
            background-color: #fff;
            box-shadow: 0 3px 18px rgba(100, 0, 0, .5);
            font-size: 16px;
        }

        .close {
            background-color: white;
            border: none;
            font-size: 18px;
            margin-left: 410px;
            margin-top: -10px;
        }

        .layui-input {
            border-radius: 5px;
            width: 300px;
            height: 40px;
            font-size: 15px;
        }

        .layui-form-item {
            margin-left: -20px;
        }

        #logoid {
            margin-top: -16px;
            padding-left: 113px;
            padding-bottom: 15px;
        }

        .layui-btn {
            margin-top: 20px;
            margin-left: -50px;
            border-radius: 5px;
            width: 350px;
            height: 40px;
            font-size: 15px;
        }

        .verity {
            width: 120px;
        }

        .font-set {
            font-size: 13px;
            text-decoration: none;
            margin-left: 120px;
        }

        a:hover {
            text-decoration: underline;
        }

        html, body {
            width: 100%;
            height: 100%;
        }

        body {
            background: url("${ctx}/resource/img/background.jpg") no-repeat;
            background-size: 100% 100%;
        }

    </style>
</head>
<body>
<form class="layui-form" action="${ctx}/doLogin" method="post">
    <input type="hidden" name="auth_code"/>
    <div class="container layui-anim layui-anim-scale">
        <!--<button class="close" title=""></button>-->
        <!--<div class="layui-form-mid layui-word-aux" style="text-align: center">-->
        <!--<span>数据魔方</span>-->
        <!--&lt;!&ndash;<img id="logoid" src="${ctx}/resource/img/doublestar.png" height="35">&ndash;&gt;-->
        <!--</div>-->
        <div class="layadmin-user-login-box layadmin-user-login-header"
             style="text-align: center; margin-top: 20px;margin-bottom:20px">
            <h2>数据魔方</h2>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="font-weight: bold">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="username" required lay-verify="user" placeholder="请输入用户名" autocomplete="off"
                       autofocus="autofocus" class="layui-input" value="admin">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="font-weight: bold">密　码</label>
            <div class="layui-input-inline">
                <input type="password" name="password" required lay-verify="password" placeholder="请输入密码"
                       autocomplete="off" class="layui-input" value="admin">
            </div>
            <!-- <div class="layui-form-mid layui-word-aux">辅助文字</div> -->
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="login" style="font-weight: bold; font-size: large">登陆
                </button>
            </div>
        </div>
    </div>
</form>
<#include '${ctx}/sys/include/common-js.html' />
<script>
    layui.use(['form', 'appJs', 'layer'], function () {
        var $ = layui.$;
        var form = layui.form
            , layer = layui.layer
            , app = layui.appJs;

        //自定义验证规则
        form.verify({
            user: function (value) {
                if (value.length < 3) {
                    return '标题至少得3个字符啊';
                }
            }
            , password: function (value) {
                if (!/^[\S]{4,12}$/.test(value)) {
                    return '密码必须4到12位，且不能出现空格';
                }
            }
        });

        $("form").bind("submit", function (e) {
            var data = {};
            $(this).serializeArray().map(function (x) {
                data[x.name] = x.value;
            });
            login(app.fields($('.layui-form')))
            return false;
        })
        //监听提交
        form.on('submit(login)', function (data) {
            login(data.field);
            return false;
        });

        function login(data) {
            $.post("${ctx}/sys/login", data, function (data) {
                if (data.code == '600') {
                    if (!data.surl) {
                        window.location = 'home';
                    } else {
                        layer.msg(data.surl);
                    }
                } else {
                    layer.msg(data.code + ':' + data.msg, {anim: 6, time: 1000});
                }
            });
        }
    });
</script>
</body>
</html>
